home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 November / CD 1 / APC0211D1.ISO / workshop / prog / files / ActivePerl-5.6.1.633-MSWin32.msi / _fea03724494669160121d194fa56abdf < prev    next >
Encoding:
Text File  |  2002-06-17  |  13.0 KB  |  621 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.  
  16. #
  17. # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
  18.  
  19. use strict;
  20. use IO::File;
  21. use Getopt::Std;
  22. use ExtUtils::MakeMaker qw(prompt);
  23.  
  24. use vars qw($opt_d $opt_o);
  25. use Config;
  26.  
  27. ##
  28. ##
  29. ##
  30.  
  31. my %cfg = ();
  32. my @cfg = ();
  33.  
  34. my($libnet_cfg,$msg,$ans,$def,$have_old);
  35.  
  36. ##
  37. ##
  38. ##
  39.  
  40. sub valid_host
  41. {
  42.  my $h = shift;
  43.  
  44.  defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
  45. }
  46.  
  47. ##
  48. ##
  49. ##
  50.  
  51. sub test_hostnames (\@)
  52. {
  53.  my $hlist = shift;
  54.  my @h = ();
  55.  my $host;
  56.  my $err = 0;
  57.  
  58.  foreach $host (@$hlist)
  59.   {
  60.    if(valid_host($host))
  61.     {
  62.      push(@h, $host);
  63.      next;
  64.     }
  65.    warn "Bad hostname: '$host'\n";
  66.    $err++;
  67.   }
  68.  @$hlist = @h;
  69.  $err ? join(" ",@h) : undef;
  70. }
  71.  
  72. ##
  73. ##
  74. ##
  75.  
  76. sub Prompt
  77. {
  78.  my($prompt,$def) = @_;
  79.  
  80.  $def = "" unless defined $def;
  81.  
  82.  chomp($prompt);
  83.  
  84.  if($opt_d)
  85.   {
  86.    print $prompt,," [",$def,"]\n";
  87.    return $def;
  88.   }
  89.  prompt($prompt,$def);
  90. }
  91.  
  92. ##
  93. ##
  94. ##
  95.  
  96. sub get_host_list
  97. {
  98.  my($prompt,$def) = @_;
  99.  
  100.  $def = join(" ",@$def) if ref($def);
  101.  
  102.  my @hosts;
  103.  
  104.  do
  105.   {
  106.    my $ans = Prompt($prompt,$def);
  107.  
  108.    $ans =~ s/(\A\s+|\s+\Z)//g;
  109.  
  110.    @hosts = split(/\s+/, $ans);
  111.   }
  112.  while(@hosts && defined($def = test_hostnames(@hosts)));
  113.  
  114.  \@hosts;
  115. }
  116.  
  117. ##
  118. ##
  119. ##
  120.  
  121. sub get_hostname
  122. {
  123.  my($prompt,$def) = @_;
  124.  
  125.  my $host;
  126.  
  127.  while(1)
  128.   {
  129.    my $ans = Prompt($prompt,$def);
  130.    $host = ($ans =~ /(\S*)/)[0];
  131.    last
  132.     if(!length($host) || valid_host($host));
  133.  
  134.    $def =""
  135.     if $def eq $host;
  136.  
  137.    print <<"EDQ";
  138.  
  139. *** ERROR:
  140.     Hostname `$host' does not seem to exist, please enter again
  141.     or a single space to clear any default
  142.  
  143. EDQ
  144.   }
  145.  
  146.  length $host
  147.     ? $host
  148.     : undef;
  149. }
  150.  
  151. ##
  152. ##
  153. ##
  154.  
  155. sub get_bool ($$)
  156. {
  157.  my($prompt,$def) = @_;
  158.  
  159.  chomp($prompt);
  160.  
  161.  my $val = Prompt($prompt,$def ? "yes" : "no");
  162.  
  163.  $val =~ /^y/i ? 1 : 0;
  164. }
  165.  
  166. ##
  167. ##
  168. ##
  169.  
  170. sub get_netmask ($$)
  171. {
  172.  my($prompt,$def) = @_;
  173.  
  174.  chomp($prompt);
  175.  
  176.  my %list;
  177.  @list{@$def} = ();
  178.  
  179. MASK:
  180.  while(1) {
  181.    my $bad = 0;
  182.    my $ans = Prompt($prompt) or last;
  183.  
  184.    if($ans eq '*') {
  185.      %list = ();
  186.      next;
  187.    }
  188.  
  189.    if($ans eq '=') {
  190.      print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
  191.      next;
  192.    }
  193.  
  194.    unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
  195.      warn "Bad netmask '$ans'\n";
  196.      next;
  197.    }
  198.  
  199.    my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
  200.    if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
  201.      warn "Bad netmask '$ans'\n";
  202.      next MASK;
  203.    }
  204.    foreach my $byte (@ip) {
  205.      if ( $byte > 255 ) {
  206.        warn "Bad netmask '$ans'\n";
  207.        next MASK;
  208.      }
  209.    } 
  210.  
  211.    my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits); 
  212.  
  213.    if ($remove) {
  214.      delete $list{$mask};
  215.    }
  216.    else {
  217.      $list{$mask} = 1;
  218.    }
  219.  
  220.   }
  221.  
  222.  [ keys %list ];
  223. }
  224.  
  225. ##
  226. ##
  227. ##
  228.  
  229. sub default_hostname
  230. {
  231.  my $host;
  232.  my @host;
  233.  
  234.  foreach $host (@_)
  235.   {
  236.    if(defined($host) && valid_host($host))
  237.     {
  238.      return $host
  239.     unless wantarray;
  240.      push(@host,$host);
  241.     }
  242.   }
  243.  
  244.  return wantarray ? @host : undef;
  245. }
  246.  
  247. ##
  248. ##
  249. ##
  250.  
  251. getopts('do:');
  252.  
  253. $libnet_cfg = "$Config{installsitelib}/Net/libnet.cfg"
  254.     unless(defined($libnet_cfg = $opt_o));
  255.  
  256. my %oldcfg = ();
  257.  
  258. $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
  259. if( -f $libnet_cfg )
  260.  {
  261.   %oldcfg = ( %{ do $libnet_cfg } );
  262.  }
  263. elsif (eval { require Net::Config }) 
  264.  {
  265.   $have_old = 1;
  266.   %oldcfg = %Net::Config::NetConfig;
  267.  }
  268.  
  269. map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
  270.  
  271. $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
  272. $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
  273.  
  274. #---------------------------------------------------------------------------
  275.  
  276. if($have_old && !$opt_d)
  277.  {
  278.   $msg = <<EDQ;
  279.  
  280. Ah, I see you already have installed libnet before.
  281.  
  282. Do you want to modify/update your configuration (y|n) ?
  283. EDQ
  284.  
  285.  $opt_d = 1
  286.     unless get_bool($msg,0);
  287.  }
  288.  
  289. #---------------------------------------------------------------------------
  290.  
  291. $msg = <<EDQ;
  292.  
  293. This script will prompt you to enter hostnames that can be used as
  294. defaults for some of the modules in the libnet distribution.
  295.  
  296. To ensure that you do not enter an invalid hostname, I can perform a
  297. lookup on each hostname you enter. If your internet connection is via
  298. a dialup line then you may not want me to perform these lookups, as
  299. it will require you to be on-line.
  300.  
  301. Do you want me to perform hostname lookups (y|n) ?
  302. EDQ
  303.  
  304. $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
  305.  
  306. print <<EDQ unless $cfg{'test_exist'};
  307.  
  308. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  309.  
  310. OK I will not check if the hostnames you give are valid
  311. so be very cafeful
  312.  
  313. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  314. EDQ
  315.  
  316.  
  317. #---------------------------------------------------------------------------
  318.  
  319. print <<EDQ;
  320.  
  321. The following questions all require a list of host names, separated
  322. with spaces. If you do not have a host available for any of the
  323. services, then enter a single space, followed by <CR>. To accept the
  324. default, hit <CR>
  325.  
  326. EDQ
  327.  
  328. $msg = 'Enter a list of available NNTP hosts :';
  329.  
  330. $def = $oldcfg{'nntp_hosts'} ||
  331.     [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
  332.  
  333. $cfg{'nntp_hosts'} = get_host_list($msg,$def);
  334.  
  335. #---------------------------------------------------------------------------
  336.  
  337. $msg = 'Enter a list of available SMTP hosts :';
  338.  
  339. $def = $oldcfg{'smtp_hosts'} ||
  340.     [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
  341.  
  342. $cfg{'smtp_hosts'} = get_host_list($msg,$def);
  343.  
  344. #---------------------------------------------------------------------------
  345.  
  346. $msg = 'Enter a list of available POP3 hosts :';
  347.  
  348. $def = $oldcfg{'pop3_hosts'} || [];
  349.  
  350. $cfg{'pop3_hosts'} = get_host_list($msg,$def);
  351.  
  352. #---------------------------------------------------------------------------
  353.  
  354. $msg = 'Enter a list of available SNPP hosts :';
  355.  
  356. $def = $oldcfg{'snpp_hosts'} || [];
  357.  
  358. $cfg{'snpp_hosts'} = get_host_list($msg,$def);
  359.  
  360. #---------------------------------------------------------------------------
  361.  
  362. $msg = 'Enter a list of available PH Hosts   :'  ;
  363.  
  364. $def = $oldcfg{'ph_hosts'} ||
  365.     [ default_hostname('dirserv') ];
  366.  
  367. $cfg{'ph_hosts'}   =  get_host_list($msg,$def);
  368.  
  369. #---------------------------------------------------------------------------
  370.  
  371. $msg = 'Enter a list of available TIME Hosts   :'  ;
  372.  
  373. $def = $oldcfg{'time_hosts'} || [];
  374.  
  375. $cfg{'time_hosts'} = get_host_list($msg,$def);
  376.  
  377. #---------------------------------------------------------------------------
  378.  
  379. $msg = 'Enter a list of available DAYTIME Hosts   :'  ;
  380.  
  381. $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
  382.  
  383. $cfg{'daytime_hosts'} = get_host_list($msg,$def);
  384.  
  385. #---------------------------------------------------------------------------
  386.  
  387. $msg = <<EDQ;
  388.  
  389. Do you have a firewall/ftp proxy  between your machine and the internet 
  390.  
  391. If you use a SOCKS firewall answer no
  392.  
  393. (y|n) ?
  394. EDQ
  395.  
  396. if(get_bool($msg,0)) {
  397.  
  398.   $msg = <<'EDQ';
  399. What series of FTP commands do you need to send to your
  400. firewall to connect to an external host.
  401.  
  402. user/pass     => external user & password
  403. fwuser/fwpass => firewall user & password
  404.  
  405. 0) None
  406. 1) -----------------------
  407.      USER user@remote.host
  408.      PASS pass
  409. 2) -----------------------
  410.      USER fwuser
  411.      PASS fwpass
  412.      USER user@remote.host
  413.      PASS pass
  414. 3) -----------------------
  415.      USER fwuser
  416.      PASS fwpass
  417.      SITE remote.site
  418.      USER user
  419.      PASS pass
  420. 4) -----------------------
  421.      USER fwuser
  422.      PASS fwpass
  423.      OPEN remote.site
  424.      USER user
  425.      PASS pass
  426. 5) -----------------------
  427.      USER user@fwuser@remote.site
  428.      PASS pass@fwpass
  429. 6) -----------------------
  430.      USER fwuser@remote.site
  431.      PASS fwpass
  432.      USER user
  433.      PASS pass
  434. 7) -----------------------
  435.      USER user@remote.host
  436.      PASS pass
  437.      AUTH fwuser
  438.      RESP fwpass
  439.  
  440. Choice:
  441. EDQ
  442.  $def = exists $oldcfg{'ftp_firewall_type'}  ? $oldcfg{'ftp_firewall_type'} : 1;
  443.  $ans = Prompt($msg,$def);
  444.  $cfg{'ftp_firewall_type'} = 0+$ans;
  445.  $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
  446.  
  447.  $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
  448. }
  449. else {
  450.  delete $cfg{'ftp_firewall'};
  451. }
  452.  
  453.  
  454. #---------------------------------------------------------------------------
  455.  
  456. if (defined $cfg{'ftp_firewall'})
  457.  {
  458.   print <<EDQ;
  459.  
  460. By default Net::FTP assumes that it only needs to use a firewall if it
  461. cannot resolve the name of the host given. This only works if your DNS
  462. system is setup to only resolve internal hostnames. If this is not the
  463. case and your DNS will resolve external hostnames, then another method
  464. is needed. Net::Config can do this if you provide the netmasks that
  465. describe your internal network. Each netmask should be entered in the
  466. form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
  467.  
  468. EDQ
  469. $def = [];
  470. if(ref($oldcfg{'local_netmask'}))
  471.  {
  472.   $def = $oldcfg{'local_netmask'};
  473.    print "Your current netmasks are :\n\n\t",
  474.     join("\n\t",@{$def}),"\n\n";
  475.  }
  476.  
  477. print "
  478. Enter one netmask at each prompt, prefix with a - to remove a netmask
  479. from the list, enter a '*' to clear the whole list, an '=' to show the
  480. current list and an empty line to continue with Configure.
  481.  
  482. ";
  483.  
  484.   my $mask = get_netmask("netmask :",$def);
  485.   $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
  486.  }
  487.  
  488. #---------------------------------------------------------------------------
  489.  
  490. ###$msg =<<EDQ;
  491. ###
  492. ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
  493. ###then enter a list of hostames
  494. ###
  495. ###Enter a list of available SOCKS hosts :
  496. ###EDQ
  497. ###
  498. ###$def = $cfg{'socks_hosts'} ||
  499. ###    [ default_hostname($ENV{SOCKS5_SERVER},
  500. ###               $ENV{SOCKS_SERVER},
  501. ###               $ENV{SOCKS4_SERVER}) ];
  502. ###
  503. ###$cfg{'socks_hosts'}   =  get_host_list($msg,$def);
  504.  
  505. #---------------------------------------------------------------------------
  506.  
  507. print <<EDQ;
  508.  
  509. Normally when FTP needs a data connection the client tells the server
  510. a port to connect to, and the server initiates a connection to the client.
  511.  
  512. Some setups, in particular firewall setups, can/do not work using this
  513. protocol. In these situations the client must make the connection to the
  514. server, this is called a passive transfer.
  515. EDQ
  516.  
  517. if (defined $cfg{'ftp_firewall'}) {
  518.   $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
  519.  
  520.   $def = $oldcfg{'ftp_ext_passive'} || 0;
  521.  
  522.   $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
  523.  
  524.   $msg = "\nShould all other FTP connections be passive (y|n) ?";
  525.  
  526. }
  527. else {
  528.   $msg = "\nShould all FTP connections be passive (y|n) ?";
  529. }
  530.  
  531. $def = $oldcfg{'ftp_int_passive'} || 0;
  532.  
  533. $cfg{'ftp_int_passive'} = get_bool($msg,$def);
  534.  
  535.  
  536. #---------------------------------------------------------------------------
  537.  
  538. $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
  539.  
  540. $ans = Prompt("\nWhat is your local internet domain name :",$def);
  541.  
  542. $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
  543.  
  544. #---------------------------------------------------------------------------
  545.  
  546. $msg = <<EDQ;
  547.  
  548. If you specified some default hosts above, it is possible for me to
  549. do some basic tests when you run `make test'
  550.  
  551. This will cause `make test' to be quite a bit slower and, if your
  552. internet connection is via dialup, will require you to be on-line
  553. unless the hosts are local.
  554.  
  555. Do you want me to run these tests (y|n) ?
  556. EDQ
  557.  
  558. $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
  559.  
  560. #---------------------------------------------------------------------------
  561.  
  562. $msg = <<EDQ;
  563.  
  564. To allow Net::FTP to be tested I will need a hostname. This host
  565. should allow anonymous access and have a /pub directory
  566.  
  567. What host can I use :
  568. EDQ
  569.  
  570. $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
  571.     if $cfg{'test_hosts'};
  572.  
  573.  
  574. print "\n";
  575.  
  576. #---------------------------------------------------------------------------
  577.  
  578. chmod(0644, $libnet_cfg);
  579. my $fh = IO::File->new($libnet_cfg, "w") or
  580.     die "Cannot create `$libnet_cfg': $!";
  581.  
  582. print "Writing $libnet_cfg\n";
  583.  
  584. print $fh "{\n";
  585.  
  586. my $key;
  587. foreach $key (keys %cfg) {
  588.     my $val = $cfg{$key};
  589.     if(!defined($val)) {
  590.     $val = "undef";
  591.     }
  592.     elsif(ref($val)) {
  593.     $val = '[' . join(",",
  594.         map {
  595.         my $v = "undef";
  596.         if(defined $_) {
  597.             ($v = $_) =~ s/'/\'/sog;
  598.             $v = "'" . $v . "'";
  599.         }
  600.         $v;
  601.         } @$val ) . ']';
  602.     }
  603.     else {
  604.     $val =~ s/'/\'/sog;
  605.     $val = "'" . $val . "'" if $val =~ /\D/;
  606.     }
  607.     print $fh "\t'",$key,"' => ",$val,",\n";
  608. }
  609.  
  610. print $fh "}\n";
  611.  
  612. $fh->close;
  613.  
  614. ############################################################################
  615. ############################################################################
  616.  
  617. exit 0;
  618.  
  619. __END__
  620. :endofperl
  621.